<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*,com.javabean.*,com.model.*" pageEncoding="UTF-8"%>
	<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.URLDecoder"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
<!--
body {
	background-color: #fff;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

.tabfont01 {
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}

.font051 {
	font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}

.font201 {
	font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}

.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}

html {
	overflow-x: auto;
	overflow-y: auto;
	border: 0;
}
-->
</style>

<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.9.0.js"></script>
<script language="JavaScript" type="text/javascript">
	function sbbj() {
		opener.document.getElementById("mainFrame");
	}
	function selectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "userNumbers") {
				obj[i].checked = true;
			}
		}
	}
	function userDelete() {
		window.open("UserDeal?flag=deleteUser");
	}
	function unselectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "userNumbers") {
				if (obj[i].checked == true)
					obj[i].checked = false;
				else
					obj[i].checked = true;
			}
		}
	}

	function link() {
		document.getElementById("fom").method = "get";
		document.getElementById("fom").action = "User_Add.jsp";
		document.getElementById("fom").submit();
	}

	function link2() {
		document.getElementById("fom").method = "get";
		document.getElementById("fom").action = "User.jsp";
		document.getElementById("fom").submit();
	}
	function link3() {
		var obj = document.fom.elements;
		var x = 0;
		for (var i=0; i<obj.length; i++ ){
		  if(obj[i].name == "userNumbers"){
			  if(obj[i].checked == true){
				  x++;
				  break;
			  }
		  }
		}
		if(x>0){
			if(confirm("确认删除所选用户？")){
				document.getElementById("fom").method = "post";
				document.getElementById("fom").action = "UserDeal?flag=userDelete";
				document.getElementById("fom").submit();
			}
		}
		else{
			window.alert("请选择需要删除的用户");
			return true;
		}
	}
	function link4() {
		if($("#textfield3").val()==""||null){
			alert("请输入页数！");
			return;
		}
		document.getElementById("fom").method = "post";
		document.getElementById("fom").action = "User.jsp?flag=go";
		document.getElementById("fom").submit();
	}

</script>
</head>
<body>
<form name="fom" id="fom" method="get" >
	
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

			<tr>
				<td height="30">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td height="62" background="../image/widgetbg5.jpg">

								<table width="98%" border="0" align="center" cellpadding="0"
									cellspacing="0">
									<tr>
										<td width="24"><img src="../images/ico07.gif" width="20"
											height="18" /></td>
										<td width="519"><select name="choice">
												<option>姓名</option>
												<option>所属部门</option>
										</select> <input name="contend" type="text" size="12" /><span
											class="newfont06" /> <input name="Submit" type="button"
											 value="查 询" onclick="link2();"/></td>
										<td width="679" align="left"><a href="#"
											onclick="sousuo()"> </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td><table id="subtree1" style="DISPLAY:" width="100%"
						border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								
									<table width="95%" border="0" align="center" cellpadding="5"
										cellspacing="0">
										<tr>
											<td height="20"><span class="newfont07">选择：<a
													href="#" class="right-font08" onclick="selectAll();">全选</a>-
													<a href="#" class="right-font08" onclick="unselectAll();">反选</a></span>


												<input name="" type="button" 
												value="删除用户" onclick="link3();"/> <input name="" type="button"
												 value="添加用户" onclick="link();" />
											</td>


										</tr>
										<tr>
											<td height="40" class="font42"><table width="100%"
													border="0" cellpadding="4" cellspacing="1"
													bgcolor="#464646" class="newfont03">
													<tr>
														<td height="20" colspan="7" align="center"
															 class="tablestyle_title">用户信息列表</td>
													</tr>
													<tr>
														<td width="5%" align="center" class="zsd">选择</td>
														<td width="15%" height="20" align="center"
															class="zsd">姓名</td>
														<td width="15%" align="center" class="zsd">工号</td>
														<td width="15%" align="center" class="zsd">所属部门</td>
														<td width="20%" align="center" class="zsd">办公地点</td>
														<td width="20%" align="center" class="zsd">是否为管理员</td>
														<td width="10%" align="center" class="zsd">操作</td>
													</tr>
													<%
														request.setCharacterEncoding("UTF-8");
														response.setCharacterEncoding("UTF-8");
														//从session中取出用户的级别
													                  int userGrade=((User)request.getSession(true).getAttribute("user")).getUserGrade();
													                  boolean isAuthority=false;
													                  if(userGrade==15){
													                	  isAuthority=true;
													                  }
													                 ArrayList<User> users=new ArrayList<User>();
													                 UserService us=new UserService();
													                 String choice=request.getParameter("choice");
													                 if(choice==null){
													                	 choice="姓名";
													                		}
													                String contend=(String)request.getParameter("contend");
													                if(contend==null){
													                	contend="";
													                }
													                String pageNow_s=(String)request.getParameter("pageNow");
													                String flag=request.getParameter("flag");
													                if("go".equals(flag)){
													                	pageNow_s=request.getParameter("goto");
													                	choice=(String)request.getParameter("gochoice");
													                	contend=(String)request.getParameter("goinput");
													                }
													                int pageNow=1;
													                int pagePrev = 0;
													        		int pageNext = 0;
													        		int pageTotal=us.getTotalPage(choice, contend);
													                if(pageNow_s!=null){
													                	pageNow=Integer.parseInt(pageNow_s);
													                }
													                if (pageNow > pageTotal || pageNow < 1)
													        			pageNow = 1;
													                if (pageNow > 1)
													        			pagePrev = pageNow - 1;
													        		else
													        			; // initial value is 0

													        		if (pageNow < pageTotal)
													        			pageNext = pageNow + 1;
													        		else
													        			; // initial value is 0	               
													               // users=us.findUsers(contend, pageNow);
													                if(choice.equals("姓名")){
													                	users=us.findUsers(contend, pageNow);
													                }else if(choice.equals("所属部门")){
													                	users=us.findUsersByDepartment(contend, pageNow);
													                }
													            
													                
													             
													                  int k=users.size();
													                   for(int i=0;i<k;i++){
													                    User user=users.get(i);
													                    String isManeger="否";
													                    if(user.getUserGrade()!=0){
													                    	isManeger="是";
													                    }
													%>
													<tr align="center">
														<td bgcolor="#FFFFFF"><input type="checkbox"
															name="userNumbers" value="<%=user.getUserNumber()%>" /></td>
														<td height="20" bgcolor="#FFFFFF"><%=user.getUserName()%></td>
														<td bgcolor="#FFFFFF"><%=user.getUserNumber()%></td>
														<td bgcolor="#FFFFFF"><%=user.getUserDepartment()%></td>
														<td bgcolor="#FFFFFF"><%=user.getUserOffice()%></td>
														<td bgcolor="#FFFFFF"><%=isManeger%></td>
														<%
															if(isAuthority){
														%>
														<td bgcolor="#FFFFFF"><a
															href="User_BJ.jsp?userNumber=<%=user.getUserNumber()%>">编辑</a></td>
													</tr>
													<%
														}
													%>
													<%
														if(!isAuthority){
													%>
													<tr>
													<td bgcolor="#FFFFFF"><span>编辑</span></td>
													</tr>
													<%
														}
													%>
													<%
														}
													%>
												</table></td>
										</tr>
									</table>
								
							</td>

						</tr>
					</table>
					<table width="95%" border="0" align="center" cellpadding="0"
						cellspacing="0">
						<tr>
							<td height="33"><table width="100%" border="0"
									align="center" cellpadding="0" cellspacing="0"
									class="right-font08">
									<tr>
										<td width="50%">共 <span class="right-text09"><%=pageTotal%></span>
											页 | 第 <span class="right-text09"><%=pageNow%></span> 页
										</td>
										<td width="49%" align="right">[<a href="User.jsp?pageNow=1&contend=<%=contend %>&choice=<%=choice %>"
											class="right-font08">首页</a> | <a
											href="User.jsp?pageNow=<%=pagePrev%>&contend=<%=contend %>&choice=<%=choice %>"
											class="right-font08">上一页</a> | <a
											href="User.jsp?pageNow=<%=pageNext%>&contend=<%=contend %>&choice=<%=choice %>"
											class="right-font08">下一页</a> | 
											<a href="User.jsp?pageNow=<%=pageTotal%>&contend=<%=contend %>&choice=<%=choice %>"
											class="right-font08">末页</a>] 转至：
										</td>
										<td width="1%"><table width="20" border="0"
												cellspacing="0" cellpadding="0">
												<tr>
												<td width="1%"><input id="textfield3" name="goto" type="text" class="right-textfield03" size="1" /></td>
                      <td width="87%"><input name="Submit23222" type="button" class="right-button06" value=" " onclick="link4()"/> </td>
                      <td width="1%"><input name="gochoice" type=hidden size="1" value="<%=choice%>" /></td>
                      <td width="1%"><input name="goinput" type="hidden" size="1" value="<%=contend%>"/></td>
												</tr>
											</table></td>
									</tr>
								</table></td>
						</tr>
					</table></td>
			</tr>
		</table>

</form>
	</body>

</html>